define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'agent/customer/index',
                    add_url: 'agent/customer/add',
                    edit_url: 'agent/customer/edit',
                    del_url: 'agent/customer/del',
                    multi_url: 'agent/customer/multi',
                    table: 'customer',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'username', title: __('Username')},
                        {field: 'password', title: __('Password')},
                        {field: 'type', title: __('Type')},
                        {field: 'avatar', title: __('Avatar')},
                        {field: 'source', title: __('Source')},
                        {field: 'identity_id', title: __('Identity_id')},
                        {field: 'tel', title: __('Tel')},
                        {field: 'social_number', title: __('Social_number')},
                        {field: 'emergency_tel', title: __('Emergency_tel')},
                        {field: 'province_id', title: __('Province_id')},
                        {field: 'city_id', title: __('City_id')},
                        {field: 'county_id', title: __('County_id')},
                        {field: 'town_id', title: __('Town_id')},
                        {field: 'village_id', title: __('Village_id')},
                        {field: 'address', title: __('Address')},
                        {field: 'real_name_auth', title: __('Real_name_auth')},
                        {field: 'indentity_picture', title: __('Indentity_picture')},
                        {field: 'email', title: __('Email')},
                        {field: 'visit_ip', title: __('Visit_ip')},
                        {field: 'remember_', title: __('Remember_')},
                        {field: 'deletetime', title: __('Deletetime')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status')},
                        {field: 'remark', title: __('Remark')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});